package com.tjbklx1.dubbo.echo;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.dubbo.rpc.service.EchoService;
import com.tjbklx1.dubbo.demo.DemoService;

/**
 * 回声测试用于检测服务是否可用，回声测试按照正常请求流程执行，能够测试整个调用是否通畅，可用于监控。 
 * 所有服务自动实现EchoService接口 (com.alibaba.dubbo.rpc.service.EchoService)，只需将任意服务引用强制转型为EchoService，即可使用。
 * @author Administrator
 *
 */
public class EchoTest {
	
	public static void main(String[] args) {
		
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "consumer.xml" });
		context.start();
		System.out.println("app run ");
		
		DemoService demoService = (DemoService) context.getBean("demoService");
		for (int i = 0; i < 10; i++) {
            EchoService echoService = (EchoService) demoService; // 强制转型为EchoService
            String status = (String) echoService.$echo("OK=" + i); // 回声测试可用性
            System.out.println(status);
        }

	}
}
